package leftMain;

import java.awt.Color;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.JTextField;

public class Scanner
{
	public Vector<String> sentences;
	public Vector<Boolean> acceptedSentences;
	public Vector<String> punctuation;
	public Vector<String> pos_1;
	public Vector<String> pos_2;
	public Vector<String> words_to_be_added;
	public Vector<String> sentence_no;
	
	public char c[], cLang;
	
	public JFrame QFrame;
		
	public JLabel label_word;
	public JLabel label_pos;
	public JTextField word;
	public JComboBox pos;
	
	public JSeparator separator_1;
	public JSeparator separator_2;
	public JLabel label_1;
		
	public JLabel label_translation_word;
	public JLabel label_translation_pos;
	public JTextField translation_word;
	public JComboBox translation_pos;
	
	public JButton add;
	public JButton cancel;
	
	public boolean b_ADDED = false;
	public boolean cont = false;
	
	public LEFTTranslator l;
	
	public boolean checkword(String str)
	{
		String query = null;
		
		try
		{	
			Class.forName("com.mysql.jdbc.Driver");
	        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/leftDB", "root","");
			
   			Statement stmt = con.createStatement();
   			
   			if(cLang == '1')
   				query = "SELECT * FROM language1Dict WHERE word = '" + str.toLowerCase() + "' ";
   			else if(cLang == '2')
   				query = "SELECT * FROM language2Dict WHERE word = '" + str.toLowerCase() + "' ";
   			ResultSet rs = stmt.executeQuery(query);
   			
   			boolean bStop = true;
   			rs.next();
			rs.getString("pos");
			
			stmt.close();
			con.close();

			return true;
			
		}
		catch(Exception e)
		{
			System.out.println("WORD NOT FOUND : " + str);
			return false;
		}
	}
	
	public boolean checkPOS(String str)
	{
		String query = null;

		try
		{
			Class.forName("com.mysql.jdbc.Driver");
	        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/leftDB", "root","");
				
	   		Statement stmt = con.createStatement();

//System.out.println("LANGUAGE = " + cLang);
	   			
	   		if(cLang == '1')
	   			query = "SELECT pos FROM language1Dict WHERE word = '" + str + "' ";
	   		else if(cLang == '2')
	   			query = "SELECT pos FROM language2Dict WHERE word = '" + str + "' ";
	   		
	   		ResultSet rs = stmt.executeQuery(query);
	   		
	   		rs.next();
	   		String pos = rs.getString("pos");

	   		if(pos.equals("proper"))
	   			return true;
	   		else if(pos.equals("proper_noun"))
	   			return true;
	   		else
	   			return false;
	   		
	   	}
	   	catch(Exception e)
		{
			return false;
		}
   		
	}
	public void scanNoGUI (String TEXT_ORIG, LEFTTranslator l)
	{
		sentences = new Vector();
		acceptedSentences = new Vector();
		punctuation = new Vector();
		words_to_be_added = new Vector();
		sentence_no = new Vector();
		
		StringTokenizer TEXT = new StringTokenizer(TEXT_ORIG);
		String strTemp = "";
		
		Vector<String> words = new Vector();
		
		int nASCII = -1;
		int nASCII_END = -1;
		int sentence_count = 0;
		boolean bStop = true;
		boolean b_MARKER = true;
		
		while(TEXT.hasMoreElements())
		{
			words.addElement(TEXT.nextToken());
		}
		
		int words_SIZE = 0;
		while(words_SIZE < words.size() && bStop)
		{
			String s = words.get(words_SIZE);
			String sTemp = "";
			
			nASCII_END = s.charAt(s.length()-1);
			
			char cASCII = s.charAt(s.length()-1);
			char[] charTemp;
			
			if(strTemp.equals(""))
			{
				nASCII = words.get(words_SIZE).toString().charAt(0);
				if(isCapital(nASCII) == false)
				{	
					if(isOpenQuote(nASCII) == true || isSingleQuote(nASCII) == true || isNumber(nASCII) == true)
					{
						if(isEnd(nASCII_END) == true)
						{

							sentence_count++;
							charTemp = s.toCharArray();
							int nTemp = 0;
							while(nTemp < s.length()-1)
							{
								sTemp = sTemp + charTemp[nTemp];
								nTemp++;
							}
							strTemp = sTemp;
							
							if(checkPOS(sTemp) == false)
								if(checkword(sTemp) == false)
									b_MARKER = false;
									
							acceptedSentences.addElement(b_MARKER);
							b_MARKER = true;

							sentences.addElement(strTemp);
							strTemp = "";
							
							punctuation.addElement(charTemp[nTemp] + "");

//System.out.println("1.1");
						}
						else if(isComma(nASCII_END) == true)
						{

							charTemp = s.toCharArray();
							int nTemp = 0;
							while(nTemp < s.length()-1)
							{
								sTemp = sTemp + charTemp[nTemp];
								nTemp++;
							}
							strTemp = sTemp + " ,";
								
							if(checkPOS(sTemp) == false)
								if(checkword(sTemp) == false)
									b_MARKER = false;
//System.out.println("1.2");
						}
						else
						{

							strTemp = s;
							if(checkPOS(s) == false)
								if(checkword(s) == false)
									b_MARKER = false;
//System.out.println("1.3");
						}
					}
					else
					{
						//printError(gui, "Sentence_" + (sentence_count+1) + '\n' + "ERROR!! Sentence must start with a capital letter!!");
						
						strTemp = findSentence(words_SIZE, words);
						sentences.addElement(strTemp);
						strTemp = "";
						words_SIZE = findEnd(words_SIZE, words);
						
						punctuation.addElement("");
						sentence_count++;
					}
					
					b_MARKER = false;
					acceptedSentences.addElement(b_MARKER);
					b_MARKER = true;
				}
				else
				{
					if(isEnd(nASCII_END) == true)
					{

						sentence_count++;
						charTemp = s.toCharArray();
						int nTemp = 0;
						while(nTemp < s.length()-1)
						{
							sTemp = sTemp + charTemp[nTemp];
							nTemp++;
						}
						strTemp = sTemp;
							
						if(checkPOS(sTemp) == false)
							if(checkword(sTemp) == false)
								if(isALLCAPS(sTemp) == true)
								{
									/*
									AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
									//a.dispose();
									a.insertIntoDatabase("1", sTemp, "proper_noun", "", "", "");
									a.insertIntoDatabase("2", sTemp, "proper", "", "", "");
									a.insertTranslation(sTemp, "proper_noun", "1", sTemp, "proper", "2");
									a.insertTranslation(sTemp, "proper", "2", sTemp, "proper_noun", "1");
									a.dispose();
									//a.refresh();
									gui.repaint();
									*/
								}
								else
								{
									words_to_be_added.addElement(sTemp);
									sentence_no.addElement((sentence_count+1)+"");
									b_MARKER = false;
								}
						
						acceptedSentences.addElement(b_MARKER);
						b_MARKER = true;
						
						sentences.addElement(strTemp);
						strTemp = "";
						
						punctuation.addElement(charTemp[nTemp] + "");
//System.out.println("1.4");
					}
					else if(isComma(nASCII_END) == true)
					{

						charTemp = s.toCharArray();
						int nTemp = 0;
						while(nTemp < s.length()-1)
						{
							sTemp = sTemp + charTemp[nTemp];
							nTemp++;
						}
						strTemp = sTemp + " ,";

						if(checkPOS(sTemp) == false)
							if(checkword(sTemp) == false)
								if(isALLCAPS(sTemp) == true)
								{
									/*
									AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
									//a.dispose();
									a.insertIntoDatabase("1", sTemp, "proper_noun", "", "", "");
									a.insertIntoDatabase("2", sTemp, "proper", "", "", "");
									a.insertTranslation(sTemp, "proper_noun", "1", sTemp, "proper", "2");
									a.insertTranslation(sTemp, "proper", "2", sTemp, "proper_noun", "1");
									a.dispose();
									a.refresh();
									gui.repaint();
									*/
								}
								else
								{
									words_to_be_added.addElement(sTemp);
									sentence_no.addElement((sentence_count+1)+"");
									b_MARKER = false;
								}	
//System.out.println("1.5");								
					}
					else
					{
						strTemp = s;
						if(checkPOS(s) == false)
							if(checkword(s) == false)
								if(isALLCAPS(s) == true)
								{
									/*
									AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
									//a.dispose();
									a.insertIntoDatabase("1", s, "proper_noun", "", "", "");
									a.insertIntoDatabase("2", s, "proper", "", "", "");
									a.insertTranslation(s, "proper_noun", "1", s, "proper", "2");
									a.insertTranslation(s, "proper", "2", s, "proper_noun", "1");
									a.refresh();
									a.dispose();
									gui.repaint();
									*/
								}
								else
								{
									words_to_be_added.addElement(s);
									sentence_no.addElement((sentence_count+1)+"");
									b_MARKER = false;
								}
								
//System.out.println("1.6");
					}
				}
			}
			else
			{
				if(isEnd(nASCII_END) == true)
				{

					sentence_count++;
					charTemp = s.toCharArray();
					int nTemp = 0;
					while(nTemp < s.length()-1)
					{
						sTemp = sTemp + charTemp[nTemp];
						nTemp++;
					}
					strTemp = strTemp + " " + sTemp;
					sentences.addElement(strTemp);
					strTemp = "";
					
					if(isALLCAPS(sTemp) == true)
						System.out.println("PROPER_NOUN");
						
					if(checkPOS(sTemp) == false)
						if(checkword(sTemp) == false)
							if(isALLCAPS(sTemp) == true)
							{
								/*
								AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
								//a.dispose();
								a.insertIntoDatabase("1", sTemp, "proper_noun", "", "", "");
								a.insertIntoDatabase("2", sTemp, "proper", "", "", "");
								a.insertTranslation(sTemp, "proper_noun", "1", sTemp, "proper", "2");
								a.insertTranslation(sTemp, "proper", "2", sTemp, "proper_noun", "1");
								a.dispose();
								a.refresh();
								gui.repaint();
								*/
							}
							else
							{
								words_to_be_added.addElement(sTemp);
								sentence_no.addElement((sentence_count+1)+"");
								b_MARKER = false;
							}
					
					acceptedSentences.addElement(b_MARKER);
					b_MARKER = true;
					
					punctuation.addElement(charTemp[nTemp] + "");
//System.out.println("2.1");
				}
				else if(isComma(nASCII_END) == true)
				{

					charTemp = s.toCharArray();
					int nTemp = 0;
					while(nTemp < s.length()-1)
					{
						sTemp = sTemp + charTemp[nTemp];
						nTemp++;
					}
					strTemp = strTemp + " " + sTemp + " ,";
					
					if(checkPOS(sTemp) == false)
						if(checkword(sTemp) == false)
							if(isALLCAPS(sTemp) == true)
							{
								/*
								AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
								//a.dispose();
								a.insertIntoDatabase("1", sTemp, "proper_noun", "", "", "");
								a.insertIntoDatabase("2", sTemp, "proper", "", "", "");
								a.insertTranslation(sTemp, "proper_noun", "1", sTemp, "proper", "2");
								a.insertTranslation(sTemp, "proper", "2", sTemp, "proper_noun", "1");
								a.dispose();
								a.refresh();
								gui.repaint();
								*/
							}
							else
							{
								words_to_be_added.addElement(sTemp);
								sentence_no.addElement((sentence_count+1)+"");
								b_MARKER = false;
							}
//System.out.println("2.2");
				}
				else
				{
					strTemp = strTemp + " " + s;
					if(checkPOS(s) == false)
						if(checkword(s) == false)
							if(isALLCAPS(s) == true)
							{
								/*
								AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
								//a.dispose();
								a.insertIntoDatabase("1", s, "proper_noun", "", "", "");
								a.insertIntoDatabase("2", s, "proper", "", "", "");
								a.insertTranslation(s, "proper_noun", "1", s, "proper", "2");
								a.insertTranslation(s, "proper", "2", s, "proper_noun", "1");
								a.dispose();
								a.refresh();
								gui.repaint();
								*/
							}
							else
							{
								words_to_be_added.addElement(s);
								sentence_no.addElement((sentence_count+1)+"");
								b_MARKER = false;
							}
//System.out.println("2.3");
				}
			}
			words_SIZE++;
		}
		
		//RunTime rt = new RunTime(cLang, this, gui);
		
		System.out.println("TOTAL_" + sentence_count);
		int NUM = 0;
		Vector<String> sentence_TEMP = new Vector();
		
		while(NUM < sentences.size())
		{
			if(acceptedSentences.get(NUM) == true)
			{
				String senTemp = "";
				String wordTemp = "";
				StringTokenizer st = new StringTokenizer(sentences.get(NUM).toString());
				while(st.hasMoreTokens())
				{
					wordTemp = st.nextToken();
					if(checkPOS(wordTemp) == false)
					{
						if(senTemp.equals(""))
							senTemp = wordTemp.toLowerCase();
						else
							senTemp = senTemp + " " + wordTemp;
					}
					else
					{
						if(senTemp.equals(""))
							senTemp = wordTemp;
						else
							senTemp = senTemp + " " + wordTemp;
					}
							
				}
				sentence_TEMP.addElement(senTemp);
			}
			else
				sentence_TEMP.addElement(sentences.get(NUM).toString());
			//System.out.println(sentences.get(NUM) + "_" + acceptedSentences.get(NUM) + "_" + punctuation.get(NUM));
			
			System.out.println(sentence_TEMP.get(NUM));
			NUM++;
		}
		
		sentences = sentence_TEMP;
	}
	
	public void scan(LeftGUI gui, String TEXT_ORIG, LEFTTranslator l)
	{
		sentences = new Vector();
		acceptedSentences = new Vector();
		punctuation = new Vector();
		words_to_be_added = new Vector();
		sentence_no = new Vector();
		
		StringTokenizer TEXT = new StringTokenizer(TEXT_ORIG);
		String strTemp = "";
		
		Vector<String> words = new Vector();
		
		int nASCII = -1;
		int nASCII_END = -1;
		int sentence_count = 0;
		boolean bStop = true;
		boolean b_MARKER = true;
		
		while(TEXT.hasMoreElements())
		{
			words.addElement(TEXT.nextToken());
		}
		
		int words_SIZE = 0;
		while(words_SIZE < words.size() && bStop)
		{
			String s = words.get(words_SIZE);
			String sTemp = "";
			
			nASCII_END = s.charAt(s.length()-1);
			
			char cASCII = s.charAt(s.length()-1);
			char[] charTemp;
			
			if(strTemp.equals(""))
			{
				nASCII = words.get(words_SIZE).toString().charAt(0);
				if(isCapital(nASCII) == false)
				{	
					if(isOpenQuote(nASCII) == true || isSingleQuote(nASCII) == true || isNumber(nASCII) == true)
					{
						if(isEnd(nASCII_END) == true)
						{

							sentence_count++;
							charTemp = s.toCharArray();
							int nTemp = 0;
							while(nTemp < s.length()-1)
							{
								sTemp = sTemp + charTemp[nTemp];
								nTemp++;
							}
							strTemp = sTemp;
							
							if(checkPOS(sTemp) == false)
								if(checkword(sTemp) == false)
									b_MARKER = false;
									
							acceptedSentences.addElement(b_MARKER);
							b_MARKER = true;

							sentences.addElement(strTemp);
							strTemp = "";
							
							punctuation.addElement(charTemp[nTemp] + "");

//System.out.println("1.1");
						}
						else if(isComma(nASCII_END) == true)
						{

							charTemp = s.toCharArray();
							int nTemp = 0;
							while(nTemp < s.length()-1)
							{
								sTemp = sTemp + charTemp[nTemp];
								nTemp++;
							}
							strTemp = sTemp + " ,";
								
							if(checkPOS(sTemp) == false)
								if(checkword(sTemp) == false)
									b_MARKER = false;
//System.out.println("1.2");
						}
						else
						{

							strTemp = s;
							if(checkPOS(s) == false)
								if(checkword(s) == false)
									b_MARKER = false;
//System.out.println("1.3");
						}
					}
					else
					{
						printError(gui, "Sentence_" + (sentence_count+1) + '\n' + "ERROR!! Sentence must start with a capital letter!!");
						
						strTemp = findSentence(words_SIZE, words);
						sentences.addElement(strTemp);
						strTemp = "";
						words_SIZE = findEnd(words_SIZE, words);
						
						punctuation.addElement("");
						sentence_count++;
					}
					
					b_MARKER = false;
					acceptedSentences.addElement(b_MARKER);
					b_MARKER = true;
				}
				else
				{
					if(isEnd(nASCII_END) == true)
					{

						sentence_count++;
						charTemp = s.toCharArray();
						int nTemp = 0;
						while(nTemp < s.length()-1)
						{
							sTemp = sTemp + charTemp[nTemp];
							nTemp++;
						}
						strTemp = sTemp;
							
						if(checkPOS(sTemp) == false)
							if(checkword(sTemp) == false)
								if(isALLCAPS(sTemp) == true)
								{
									AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
									//a.dispose();
									a.insertIntoDatabase("1", sTemp, "proper_noun", "", "", "");
									a.insertIntoDatabase("2", sTemp, "proper", "", "", "");
									a.insertTranslation(sTemp, "proper_noun", "1", sTemp, "proper", "2");
									a.insertTranslation(sTemp, "proper", "2", sTemp, "proper_noun", "1");
									a.dispose();
									a.refresh();
									gui.repaint();
								}
								else
								{
									words_to_be_added.addElement(sTemp);
									sentence_no.addElement((sentence_count+1)+"");
									b_MARKER = false;
								}
						
						acceptedSentences.addElement(b_MARKER);
						b_MARKER = true;
						
						sentences.addElement(strTemp);
						strTemp = "";
						
						punctuation.addElement(charTemp[nTemp] + "");
//System.out.println("1.4");
					}
					else if(isComma(nASCII_END) == true)
					{

						charTemp = s.toCharArray();
						int nTemp = 0;
						while(nTemp < s.length()-1)
						{
							sTemp = sTemp + charTemp[nTemp];
							nTemp++;
						}
						strTemp = sTemp + " ,";

						if(checkPOS(sTemp) == false)
							if(checkword(sTemp) == false)
								if(isALLCAPS(sTemp) == true)
								{
									AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
									//a.dispose();
									a.insertIntoDatabase("1", sTemp, "proper_noun", "", "", "");
									a.insertIntoDatabase("2", sTemp, "proper", "", "", "");
									a.insertTranslation(sTemp, "proper_noun", "1", sTemp, "proper", "2");
									a.insertTranslation(sTemp, "proper", "2", sTemp, "proper_noun", "1");
									a.dispose();
									a.refresh();
									gui.repaint();
								}
								else
								{
									words_to_be_added.addElement(sTemp);
									sentence_no.addElement((sentence_count+1)+"");
									b_MARKER = false;
								}	
//System.out.println("1.5");								
					}
					else
					{
						strTemp = s;
						if(checkPOS(s) == false)
							if(checkword(s) == false)
								if(isALLCAPS(s) == true)
								{
									AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
									//a.dispose();
									a.insertIntoDatabase("1", s, "proper_noun", "", "", "");
									a.insertIntoDatabase("2", s, "proper", "", "", "");
									a.insertTranslation(s, "proper_noun", "1", s, "proper", "2");
									a.insertTranslation(s, "proper", "2", s, "proper_noun", "1");
									a.refresh();
									a.dispose();
									gui.repaint();
								}
								else
								{
									words_to_be_added.addElement(s);
									sentence_no.addElement((sentence_count+1)+"");
									b_MARKER = false;
								}
								
//System.out.println("1.6");
					}
				}
			}
			else
			{
				if(isEnd(nASCII_END) == true)
				{

					sentence_count++;
					charTemp = s.toCharArray();
					int nTemp = 0;
					while(nTemp < s.length()-1)
					{
						sTemp = sTemp + charTemp[nTemp];
						nTemp++;
					}
					strTemp = strTemp + " " + sTemp;
					sentences.addElement(strTemp);
					strTemp = "";
					
					if(isALLCAPS(sTemp) == true)
						System.out.println("PROPER_NOUN");
						
					if(checkPOS(sTemp) == false)
						if(checkword(sTemp) == false)
							if(isALLCAPS(sTemp) == true)
							{
								AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
								//a.dispose();
								a.insertIntoDatabase("1", sTemp, "proper_noun", "", "", "");
								a.insertIntoDatabase("2", sTemp, "proper", "", "", "");
								a.insertTranslation(sTemp, "proper_noun", "1", sTemp, "proper", "2");
								a.insertTranslation(sTemp, "proper", "2", sTemp, "proper_noun", "1");
								a.dispose();
								a.refresh();
								gui.repaint();
							}
							else
							{
								words_to_be_added.addElement(sTemp);
								sentence_no.addElement((sentence_count+1)+"");
								b_MARKER = false;
							}
					
					acceptedSentences.addElement(b_MARKER);
					b_MARKER = true;
					
					punctuation.addElement(charTemp[nTemp] + "");
//System.out.println("2.1");
				}
				else if(isComma(nASCII_END) == true)
				{

					charTemp = s.toCharArray();
					int nTemp = 0;
					while(nTemp < s.length()-1)
					{
						sTemp = sTemp + charTemp[nTemp];
						nTemp++;
					}
					strTemp = strTemp + " " + sTemp + " ,";
					
					if(checkPOS(sTemp) == false)
						if(checkword(sTemp) == false)
							if(isALLCAPS(sTemp) == true)
							{
								AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
								//a.dispose();
								a.insertIntoDatabase("1", sTemp, "proper_noun", "", "", "");
								a.insertIntoDatabase("2", sTemp, "proper", "", "", "");
								a.insertTranslation(sTemp, "proper_noun", "1", sTemp, "proper", "2");
								a.insertTranslation(sTemp, "proper", "2", sTemp, "proper_noun", "1");
								a.dispose();
								a.refresh();
								gui.repaint();
							}
							else
							{
								words_to_be_added.addElement(sTemp);
								sentence_no.addElement((sentence_count+1)+"");
								b_MARKER = false;
							}
//System.out.println("2.2");
				}
				else
				{
					strTemp = strTemp + " " + s;
					if(checkPOS(s) == false)
						if(checkword(s) == false)
							if(isALLCAPS(s) == true)
							{
								AddEntryGUI a =	new AddEntryGUI(gui.getX(), gui.getY(), l);
								//a.dispose();
								a.insertIntoDatabase("1", s, "proper_noun", "", "", "");
								a.insertIntoDatabase("2", s, "proper", "", "", "");
								a.insertTranslation(s, "proper_noun", "1", s, "proper", "2");
								a.insertTranslation(s, "proper", "2", s, "proper_noun", "1");
								a.dispose();
								a.refresh();
								gui.repaint();
							}
							else
							{
								words_to_be_added.addElement(s);
								sentence_no.addElement((sentence_count+1)+"");
								b_MARKER = false;
							}
//System.out.println("2.3");
				}
			}
			words_SIZE++;
		}
		
		//RunTime rt = new RunTime(cLang, this, gui);
		
		System.out.println("TOTAL_" + sentence_count);
		int NUM = 0;
		Vector<String> sentence_TEMP = new Vector();
		
		while(NUM < sentences.size())
		{
			if(acceptedSentences.get(NUM) == true)
			{
				String senTemp = "";
				String wordTemp = "";
				StringTokenizer st = new StringTokenizer(sentences.get(NUM).toString());
				while(st.hasMoreTokens())
				{
					wordTemp = st.nextToken();
					if(checkPOS(wordTemp) == false)
					{
						if(senTemp.equals(""))
							senTemp = wordTemp.toLowerCase();
						else
							senTemp = senTemp + " " + wordTemp;
					}
					else
					{
						if(senTemp.equals(""))
							senTemp = wordTemp;
						else
							senTemp = senTemp + " " + wordTemp;
					}
							
				}
				sentence_TEMP.addElement(senTemp);
			}
			else
				sentence_TEMP.addElement(sentences.get(NUM).toString());
			//System.out.println(sentences.get(NUM) + "_" + acceptedSentences.get(NUM) + "_" + punctuation.get(NUM));
			
			System.out.println(sentence_TEMP.get(NUM));
			NUM++;
		}
		
		sentences = sentence_TEMP;
	}
	
	public void printError(LeftGUI gui, String errMessage)
	{
		javax.swing.JOptionPane.showMessageDialog(gui, errMessage, "Error!!", javax.swing.JOptionPane.ERROR_MESSAGE);
	}

	public int findEnd(int current, Vector<String> words)
	{
		boolean bEnd = true;
		int nASCII_END = -1;
		
		while(bEnd)
		{
			String s = words.get(current);
			nASCII_END = s.charAt(s.length()-1);
			
			if(checkPOS(s) == false)
				checkword(s);
			
			if(isEnd(nASCII_END) == true)
				bEnd = false;
			else
				current++;
		}
		return current;
	}
	
	public String findSentence(int current, Vector<String> words)
	{
		boolean bEnd = true;
		int nASCII_END = -1;
		String str = "";
		
		while(bEnd)
		{
			String s = words.get(current);
			nASCII_END = s.charAt(s.length()-1);
			
			if(isEnd(nASCII_END) == true)
				bEnd = false;
			else
				current++;
			
			if(!str.equals(""))	
				str = str + " " + s;
			else
				str = s;
		}
		
		return str;
	}
	
	public boolean isEnd(int temp)
	{
		if(temp == 33 || temp == 46 || temp == 63)
			return true;
		else
			return false;
	}
	
	public boolean isOpenQuote(int temp)
	{
		if(temp == 39)
			return true;
		else
			return false;
	}
	
	public boolean isSingleQuote(int temp)
	{
		if(temp == 34)
			return true;
		else
			return false;
	}
	
	public boolean isNumber(int temp)
	{
		if(temp >47 && temp < 58)
			return true;
		else
			return false;	
	}
	
	public boolean isComma(int temp)
	{
		if(temp == 44)
			return true;
		else
			return false;
	}
	
	public boolean isCapital(int temp)
	{
		if(temp > 64 && temp < 91)
			return true;
		else
			return false;
	}
	
	public boolean isALLCAPS(String str)
	{
		int z = 0;
		int temp;
		boolean b = true;
		while(z < str.length() && b)
		{
			temp = str.charAt(z);
			if(isCapital(temp) == true)
				z++;
			else
				b = false;
		}
		
		return b;
	}
	
	public boolean checker(String str)
	{
		if(str.equals("Mr"))
			return true;
		else if(str.equals("Ms"))
			return true;
		else if(str.equals("Dr"))
			return true;
		else
			return false;
	}
	
	public void init(String s)
	{	
		QFrame = new JFrame("Add word?");
		
		label_word = new JLabel("Word:*");
		label_pos = new JLabel("Part of Speech:*");
	  	word = new JTextField("sample");
	  	pos = new JComboBox();

	  	separator_1 = new JSeparator();
	  	separator_2 = new JSeparator();
	  	label_1 = new JLabel("Translation");

	  	label_translation_word = new JLabel("Word:*");
	  	label_translation_pos = new JLabel("Part of Speech:*");
	  	translation_word = new JTextField();
	  	translation_pos = new JComboBox();
	
	  	add = new JButton("Add");
	  	cancel = new JButton("Cancel");
		
		textReader('1');
		textReader('2');
		int a = 0;
		pos.addItem("Please Choose . . .");
		translation_pos.addItem("Please Choose . . .");
		if(cLang == '1')
		{
			while(a < pos_1.size())
			{
				pos.addItem(pos_1.get(a));
				a++;
			}
			a= 0;
			while(a < pos_1.size())
			{
				translation_pos.addItem(pos_2.get(a));
				a++;
			}
		}
		else
		{
			while(a < pos_2.size())
			{
				pos.addItem(pos_2.get(a));
				a++;
			}
			a = 0;
			while(a < pos_1.size())
			{
				translation_pos.addItem(pos_1.get(a));
				a++;
			}
		}
		
		QFrame.setTitle("Add word??" + " _" + s + "_" );
		QFrame.setBounds(200, 100, 420, 215);
		QFrame.getContentPane().setLayout(null);
		QFrame.setResizable(false);
		/*QFrame.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				//QFrame.dispose();
				//System.exit(0);
			}
		});*/
		
		//WORD:
		label_word.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		label_word.setBounds(15, 7, 160, 25);
		QFrame.getContentPane().add(label_word);
		
		word.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		word.setText(s);
		word.setEditable(true);
		word.setBackground(Color.white);
		word.setBounds(165, 7, 230, 25);
		word.setEditable(false);
		QFrame.getContentPane().add(word);
		
		//PART OF SPEECH
		label_pos.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		label_pos.setBounds(15, 37, 160, 25);
		QFrame.getContentPane().add(label_pos);
		
		pos.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		pos.setBackground(Color.white);
		pos.setBounds(165, 37, 230, 25);
		QFrame.getContentPane().add(pos);
		
		//SEPARATOR
		separator_1.setBounds(15, 75, 150, 5);
		QFrame.getContentPane().add(separator_1);
		
		separator_2.setBounds(245, 75, 150, 5);
		QFrame.getContentPane().add(separator_2);
		
		//LABEL_1
		label_1.setFont(new java.awt.Font("Microsoft Sans Serif", 3, 12));
		label_1.setBounds(168, 70, 90, 10);
		QFrame.getContentPane().add(label_1);
		
		//TRANSLATION_WORD
		label_translation_word.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		label_translation_word.setBounds(15, 90, 160, 25);
		QFrame.getContentPane().add(label_translation_word);
		
		translation_word.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		translation_word.setText("");
		translation_word.setEditable(true);
		translation_word.setBackground(Color.white);
		translation_word.setBounds(165, 90, 230, 25);
		QFrame.getContentPane().add(translation_word);
		
		
		//TRANSLATE_POS
		label_translation_pos.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		label_translation_pos.setBounds(15, 120, 160, 25);
		QFrame.getContentPane().add(label_translation_pos);
		
		translation_pos.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		translation_pos.setBackground(Color.white);
		translation_pos.setBounds(165, 120, 230, 25);
		QFrame.getContentPane().add(translation_pos);
		
		//BUTTONS
		add.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		add.setToolTipText("Add");
		add.setBounds(195, 150, 100, 25);
		add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                if(pos.getSelectedIndex() != 0 && !translation_word.getText().equals("") && translation_pos.getSelectedIndex() != 0)
            	{
            		javax.swing.JOptionPane.showMessageDialog(QFrame, "Word successfully added.");
            		QFrame.dispose();
            		cont = true;
            	}
            	else
            		javax.swing.JOptionPane.showMessageDialog(QFrame, "Required fields missing. (*)", "Error!!", javax.swing.JOptionPane.ERROR_MESSAGE);
            }
        });
		QFrame.getContentPane().add(add);
		
		cancel.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 16));
		cancel.setToolTipText("Cancel");
		cancel.setBounds(295, 150, 100, 25);
		cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                if(b_ADDED == true)
                {
                	QFrame.dispose();
                	cont = true;
                }
                else
                {
					int answer = javax.swing.JOptionPane.showConfirmDialog(QFrame, "You have not yet added the word.\nWould you like to add it first?", "Warning!!", javax.swing.JOptionPane.YES_NO_OPTION);
                	if(answer == 1)
                	{
                		javax.swing.JOptionPane.showMessageDialog(QFrame, "Warning!! Sentence will not be translated.", "Warning!!", javax.swing.JOptionPane.ERROR_MESSAGE);
                		QFrame.dispose();
                		cont = true;
                	}
                }
            }
        });
		QFrame.getContentPane().add(cancel);
		
		QFrame.setVisible(true);
		QFrame.repaint();
		
	}
	
	public void textReader(char lang)
	{
		String textmessage = "";	
		StringTokenizer tokens;
		String filename;
		
		if(lang == '1')
		{
			pos_1 = new Vector();
			filename = "/home/pckid/LEFT/language1.txt";
		}
		else
		{
			pos_2 = new Vector();
			filename = "/home/pckid/LEFT/language2.txt";
		}
		
		try
		{
			BufferedReader in = new BufferedReader (new FileReader (filename));
			String line;
			
			while ((line = in.readLine()) != null)
			{					
				textmessage = textmessage + line;
				textmessage = textmessage + "\n";
			}
			tokens = new StringTokenizer(textmessage);
			if(lang == '1')
				pos_1 = get_pos(tokens);
			else
				pos_2 = get_pos(tokens);
			
			in.close();
		}
		catch (IOException ex1)
		{
		  	
      		System.err.println("IO Exception (main): " + ex1.getMessage());
       	}	
	}
	
	public Vector<String> get_pos(StringTokenizer strTokens)
	{
		boolean b = true;
		Vector<String> pos = new Vector();
		while(strTokens.hasMoreElements() && b)
		{
			if(strTokens.nextElement().equals("Terminals:"))
			{
				String temp = "";
				while(b)
				{
					temp = strTokens.nextElement().toString();
					if(!temp.equals("NonTerminals:"))
						pos.add(temp);
					else
						b = false;
				}
			}
		}
		return pos;
	}

}